package com.example.guiguiapplicatio.fragment.Fulfillment.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.guiguiapplicatio.R;
import com.example.guiguiapplicatio.Response.Fulfillment;
import com.example.guiguiapplicatio.Response.ServicePackServiceitems;
import com.example.guiguiapplicatio.Response.Serviceitems;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class FulfillmentitemsDetailAdapter extends RecyclerView.Adapter<FulfillmentitemsDetailAdapter.FulfillmentitemsDetailViewHolder>{
    private Context mContext;
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");

    private List<Fulfillment> FulfillmentitemsList;
    public FulfillmentitemsDetailAdapter(List<Fulfillment> serviceitemslist, Context context) {
        this.FulfillmentitemsList = serviceitemslist;
    }
    @NonNull
    @Override
    public FulfillmentitemsDetailViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fulfillment_service_items, parent, false);
        return new FulfillmentitemsDetailViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FulfillmentitemsDetailViewHolder holder, int position) {
        Fulfillment fulfillment =FulfillmentitemsList.get(position);
        String StartTime = dateFormat.format(fulfillment.getFulfillmentTime());
        String NextTime = dateFormat.format(fulfillment.getFulfillmentNexttime());
        holder.FulfillmentservicepackagenameTextView.setText(fulfillment.getName());
        holder.FulfillmentservicepackageitemnameTextView.setText(fulfillment.getServiceItemsName());
        holder.FulfillmentservicepackageitemnumberTextView.setText(fulfillment.getCompletions());
        holder.FulfillmentservicepackageitemStarttimeTextView.setText(StartTime);
        holder.FulfillmentservicepackageitemnexttimeTextView.setText(NextTime);
        holder.FulfillmentservicepackageitemcontentTextView.setText(fulfillment.getFulfillmentContract());
        holder.FulfillmentservicepackageitemefficiencyTextView.setText(fulfillment.getFulfillmentEfficiency());
    }

    @Override
    public int getItemCount() {
        return FulfillmentitemsList.size();
    }
    public void setData(List<Fulfillment> data) {
        if (data == null) {
            data = new ArrayList<>();
        }
        this.FulfillmentitemsList = data;
    }

    public static class FulfillmentitemsDetailViewHolder extends RecyclerView.ViewHolder {
        TextView FulfillmentservicepackagenameTextView;
        TextView FulfillmentservicepackageitemnameTextView;
        TextView FulfillmentservicepackageitemnumberTextView;
        TextView FulfillmentservicepackageitemStarttimeTextView;
        TextView FulfillmentservicepackageitemnexttimeTextView;
        TextView FulfillmentservicepackageitemcontentTextView;
        TextView FulfillmentservicepackageitemefficiencyTextView;


        public FulfillmentitemsDetailViewHolder(@NonNull View itemView) {
            super(itemView);
            FulfillmentservicepackagenameTextView = itemView.findViewById(R.id.Fulfillment_service_package_name);
            FulfillmentservicepackageitemnameTextView = itemView.findViewById(R.id.Fulfillment_service_package_item_name);
            FulfillmentservicepackageitemnumberTextView = itemView.findViewById(R.id.Fulfillment_service_package_item_number);
            FulfillmentservicepackageitemStarttimeTextView = itemView.findViewById(R.id.Fulfillment_service_package_item_Start_time);
            FulfillmentservicepackageitemnexttimeTextView = itemView.findViewById(R.id.Fulfillment_service_package_item_next_time);
            FulfillmentservicepackageitemcontentTextView = itemView.findViewById(R.id.Fulfillment_service_package_item_content);
            FulfillmentservicepackageitemefficiencyTextView = itemView.findViewById(R.id.Fulfillment_service_package_item_efficiency);
        }
    }
}
